
function changeModelColorLoading(self, tiyData) {
  tiyData.tStatus.modifyModal.isLoading = false;
  self.$nextTick(function () {
    tiyData.tStatus.modifyModal.isLoading = true;
  });
}

export const init = (self, tiyData) => {
  tiyData.tPage.currentPage = 1;
  tiyData.tPage.stepNumber = 40;
  tiyData.tParam.postageName = '';
  tiyData.tStatus.editMode.isEdit = false;
  tiyData.tStatus.editMode.selectedTab = "Android";
  tiyData.tStatus.editMode.btnName = "编辑";
}

export const webData = (self, tiyData) => {
  self.$Spin.show();
  self.$apiOther.getAppVersion({})
    .then(function (response) {
      self.$Spin.hide();
      if (response.success) {
        for(let prop in tiyData.tData.android){
          tiyData.tData.android[prop] = response.result.android[prop];
        }
        for(let prop in tiyData.tData.android){
          tiyData.tData.ios[prop] = response.result.ios[prop];
        }
      } else {
        self.$Spin.hide();
        self.$Message.error(response.errorMessage);
      }
    });
};

export const saveVersion = (self, tiyData) => {
  let formName = tiyData.tStatus.editMode.selectedTab == "Android" ? "androidForm" : "iosForm";
  let saveData = tiyData.tStatus.editMode.selectedTab == "Android" ? self.android : self.ios;
  self.$refs[formName].validate((valid) => {
    if (valid) {
      self.$Spin.show();
      self.$apiOther.saveAppVersion({
        versionData:saveData
      }).then(function (response) {
        self.$Spin.hide();
        if (response.success) {
          webData(self, tiyData);
          self.$Message.success((tiyData.tStatus.editMode.selectedTab == "Android" ? "android" : "ios") + '版本信息保存成功!');
          tiyData.tStatus.editMode.isEdit = false;
          tiyData.tStatus.editMode.btnName = "编辑";
          self.iosDisablse = false;
          self.androidDisablse = false;
        } else {
          self.$Message.error(response.errorMessage);
        }
      });
    }
  });

};

